import * as constants from './constants';
import { fromJS } from 'immutable';
import {getTypeData,ableType,disableType,impowerType,saveEditor,
    deleteCon,getSupData,addCataType,getOrgImpower}  from '../../../../api/config/config'

// const changeMenu = (current) => ({
//   type: constants.CHANGE_MENU,
//   current,
// });

// export const changeMenuOperation = (current) => {
//   return(dispatch) => {
//     dispatch(changeMenu(current));
//   }
// };
const getAllTypeInfo=(dispatch)=>{
             const token=localStorage.getItem('Token');  
                getTypeData(token).then(res=>{
                        if(res.status===200){
                                console.log(res);
                                const dataList=res.data.data.list;
                                dispatch({
                                type:'get_all_type',
                                resourceType:dataList,
                                typePageNum:Math.ceil(dataList.length/10)
                                })
                        }
                })
}
export const getAllType=()=>{
        return(dispatch)=>{
                getAllTypeInfo(dispatch);
}
} 
export const startTypeEnable=(number)=>{
    const token=localStorage.getItem('Token');
    return(dispatch)=>{
           ableType(token,number).then(res=>{
               if(res.status===200){
                   console.log(res);
                   getAllTypeInfo(dispatch);
               }
           })
    }
}
export const noTypeEnable=(number)=>{
    const token=localStorage.getItem('Token');
    return(dispatch)=>{
           disableType(token,number).then(res=>{
               if(res.status===200){
                   console.log(res);
                   getAllTypeInfo(dispatch);
               }
           })
    }
}
export const typeImpower=(number,orgId)=>{
    const token=localStorage.getItem('Token');
    return(dispatch)=>{
        impowerType(token,number,orgId).then(res=>{
            if(res.status===200){
                console.log(res);
            }
        })
    }
}
export const saveEdit=(editValue)=>{
    const token=localStorage.getItem('Token');
    return(dispatch)=>{
        saveEditor(token,editValue).then(res=>{
            if(res.status===200){
                console.log(res);
                getAllTypeInfo(dispatch)
            }
        })
    }
}
export const deleteItem=(number)=>{
    const token=localStorage.getItem('Token');
    return(dispatch)=>{
        deleteCon(token,number).then(res=>{
            if(res.status===200){
                console.log(res);
                getAllTypeInfo(dispatch)
            }
        })
    }
}
export const getSupSelect=()=>{
    const token=localStorage.getItem('Token');
    return(dispatch)=>{
        getSupData(token).then(res=>{
            dispatch({
                type:'all_select_sup',
                allResource:res.data.data,
            })
        })
    }
}
export const addType=(addValue)=>{
    const token=localStorage.getItem('Token');
    return(dispatch)=>{
        addCataType(token,addValue).then(res=>{
            if(res.status===200){
               console.log(res);
               getAllTypeInfo(dispatch)
            }
        })
    }
}
export const getAllOrg=()=>{
    const token=localStorage.getItem('Token');
    return(dispatch)=>{
        getOrgImpower(token).then(res=>{
            if(res.status===200){
                dispatch({
                    type:'get_all_orgData',
                    orgIdArr:res.data.data
                })
            }
        })
    }
}